#include "mathlink.h"

#include <math.h>
#include <stdlib.h>
#include <stdio.h>


extern void DistTable( double * coord, long coordLen);

void DistTable( double * coord, long coordLen)
{
	int coord_num;
	coord_num = coordLen / 3;

	double * pDist = (double *) malloc(coord_num * (coord_num + 1) / 2 * sizeof (double));
	double dx, dy, dz;

	int i, j, count;
	
	count = 0;
	for(i = 0; i < coord_num; i++)
	{
		for(j = 0; j < coord_num; j++)
		{
			if(i >= j)
			{
				dx = coord[3*i+0] - coord[3*j+0];
				dy = coord[3*i+1] - coord[3*j+1];
				dz = coord[3*i+2] - coord[3*j+2];
				pDist[count] = sqrt(dx*dx + dy*dy + dz*dz);
				count ++;	
			}
		}
	}



	MLPutReal64List(stdlink, pDist, coord_num * (coord_num + 1) / 2);
	
	return;	
}



int main(int argc, char* argv[])
{
	return MLMain(argc, argv);
}

